package 蓝桥杯;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
	static int ans = 0;
	static long num = 2021041820210418L;
	
	private static void dfs(List<Long> list, Long[] arr, long prod, int cnt) {
		if (cnt == 3) {
			if (prod == num) {
				// 打印满足条件的三个因数
				for (long x : list) {
					System.out.print(x + " ");	
				}
				System.out.println();
				ans++;
			}
			return;
		}
		
		for (int i = 0; i < arr.length; i++) {
			long next = prod * arr[i];
			if (next > num) {
				break;
			}
			list.add(arr[i]);
			dfs(list, arr, next, cnt + 1);
			list.remove(list.size() - 1);
		}
	}
	
	public static void main(String[] args) {
		long end = (long)Math.sqrt(num);
		Set<Long> div = new HashSet<>();
		
		for (long i = 1; i <= end; i++) {
			if (num % i == 0) {
				div.add(num / i);
				div.add(i);
			}
		}
		
		// System.out.println(div.size()); -> 128;
        List<Long> list = new ArrayList<>();
        Long[] arr = div.toArray(new Long[0]);
        // ==== 21/04/19 update 排序预处理 ====
        Arrays.sort(arr);
        // ==== 21/04/19 update 排序预处理 ====
        for (long x : arr) {
            list.add(x);
            dfs(list, arr, x, 1);
            list.remove(list.size() - 1);
        }
        System.out.println("ans = " + ans); // 28? No 2430? Yes
    }

}
